/*
 * ImageAnalyzer.h
 *
 *  Created on: 10/09/2011
 *      Author: solnox
 */

#ifndef IMAGEANALYZER_H_
#define IMAGEANALYZER_H_

#include "opencv2/opencv.hpp"
#include "AnalyzedImage.h"
class ImageAnalyzer {
public:
	static ImageAnalyzer & getInstance()
	{
		static ImageAnalyzer instance;
		return instance;
	}
	void detectKeyPoints( const cv::Mat& image, std::vector<cv::KeyPoint>& keypoints );
	void computeDescriptors( const cv::Mat& image, std::vector<cv::KeyPoint>& keypoints, cv::Mat& descriptors );
	void match(const AnalyzedImage & img1, const AnalyzedImage & img2, std::vector<cv::DMatch>& matches);
private:
	void getSingleMatches(std::vector<std::vector<cv::DMatch> > & matches1to2 ,std::vector<cv::DMatch> & single_matches1to2);
	void getSingleReversedMatches(std::vector<std::vector<cv::DMatch> > & matches1to2 ,std::vector<cv::DMatch> & single_matches1to2);

	void crossCheckMatch( const cv::Mat& desc1, const cv::Mat& desc2,
			std::vector<cv::DMatch>& common_matches, float maxDistance);
	ImageAnalyzer();
	virtual ~ImageAnalyzer();
	cv::SurfDescriptorExtractor surf_;
	cv::Ptr<cv::FeatureDetector> fd_;
	cv::BruteForceMatcher<cv::L2<float> > desc_matcher_;
	float max_distance_ ;
};

#endif /* IMAGEANALYZER_H_ */
